/*
 * @Author: 吴世扬 18368095041@163.com
 * @Date: 2024-08-16 08:16:57
 * @LastEditors: 吴世扬 18368095041@163.com
 * @LastEditTime: 2024-08-16 08:21:27
 * @FilePath: /vue3-uniapp/src/service/hook/useBeforeAuth.ts
 */
import { Subject } from 'rxjs';

const beforeAuthSubject = new Subject();
const beforeAuth$ = beforeAuthSubject.pipe();

export const triggerBeforeAuth = () => {
    beforeAuthSubject.next(undefined);
};

export const useBeforeAuth = (fn: () => void) => {
    const beforeAuthSubscription = beforeAuth$.subscribe({
        next: () => {
            fn();
        }
    });
    onBeforeUnmount(() => {
        beforeAuthSubscription?.unsubscribe();
    });
};
